<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/TemplateAD.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>CircleU - Administrator</title>
<?php
 	session_start(); 
	if( !$_SESSION["login"] || !isset($_SESSION["AdminID"]))header('Location: error_page.php');
	include("db_util.php");
	putenv("ORACLE_HOME=/usr/local/libexec/oracle/app/oracle/product/11.2.0/client_1");
	$connection=DbConnect();
	if(!$connection)
		echo "DisConnected!<br>";
	$query='SELECT * FROM Administrator where AID=' . $_SESSION["AdminID"]; 
	$statement = oci_parse($connection, $query);
	oci_execute($statement);
	$admin = oci_fetch_array($statement, OCI_ASSOC+OCI_RETURN_NULLS);
	oci_free_statement($statement);
	
	// Yan Qiao
	$check_failed = false;
	$course_added = false;
	if(isset($_POST["submit"])){
		if($_POST["CourseID"]==""||!is_numeric($_POST["CourseID"])){
			$check_failed = true;
			$error_msg = "Please enter a numberic Course ID.";
		}elseif($_POST["CourseName"]==""){
			$check_failed = true;
			$error_msg = "Please enter a Course Name.";
		} elseif($_POST["Semester"]=="NULL"){
			$check_failed = true;
			$error_msg = "Please select a Course Semester.";
		}elseif(strlen($_POST["Description"])>=500){
			$check_failed = true;
			$error_msg = "Description too long! Should not exceed 500 characters.";
		}else{
			if(db_course_exists($connection, $_POST["CourseID"])){
				$check_failed = true;
				$error_msg = "Course ID " . $_POST["CourseID"] . " already exists.";
			}else{
				if(db_add_course($connection)){
					//header('Location: AdminCourseAdded.php');
					$course_added = true;
	//				echo "Done";
				}
				else{
					$check_failed = true;
					$error_msg = "Internal error. Can not add course.";
				}
			}
		}
	}
	
	function db_add_course($con){
		$query = "insert into course(CID, Cname, Semester, Instructor, Location, Lecture_time, TA, Office_hours, Description) values(" .
				 $_POST["CourseID"] . ", '" . $_POST["CourseName"] . "', '" . $_POST["Semester"] . "', " .
				 ($_POST["Inname"]==""?"null":("'" . $_POST["Inname"] . "'")) . ", " .
				 ($_POST["Location"]==""?"null":("'" . $_POST["Location"] . "'")) . ", " .
				 ($_POST["Time"]==""?"null":("'" . $_POST["Time"] . "'")) . ", " .
				 ($_POST["TA"]==""?"null":("'" . $_POST["TA"] . "'")) . ", ".
				 ($_POST["Officehours"]==""?"null":("'" . $_POST["Officehours"] . "'")) . "," . 
				 ($_POST["Description"]==""?"null":("'" . filter_var($_POST["Description"], FILTER_SANITIZE_MAGIC_QUOTES) . "'")) . ")";
		$stmt = oci_parse($con, $query);
		if(!$stmt)
			return false;
		oci_execute($stmt);
		oci_free_statement($stmt);
		return true;
	}
?>
<!-- InstanceEndEditable -->
<style type="text/css">
<!--

a:link   {
text-decoration:   none;
}
a:visited   {
text-decoration:   none;
}
a:hover   {
text-decoration:   underline;
} 
.try {
	background-color: #FFFFFF;
	position: relative;
	z-index: auto;
	visibility: visible;
	clip: rect(auto,auto,auto,auto);
	width: auto;
	height: 76px;
}
.copyright {
	position: absolute;
	left: 236px;
	top: 600px;
	font-size: large;
	height: 22px;
}
.LayerImg {
	left: auto;
}
.CircleU {
	font-family: "Comic Sans MS";
	font-size: xx-large;
	font-weight: bold;
	position: relative;
	left: 20px;
	top: auto;
	height: auto;
	width: auto;
	visibility: visible;
	background-position: left;
	color: #3333FF;
}
#Title1 {
	position:absolute;
	width:1096px;
	height:60px;
	z-index:2;
	left: 9px;
	top: 6px;
}



}

#Dwt01 {
	position:absolute;
	width:1092px;
	height:500px;
	right: 9px;
	top: 80px;
}
#LeftLayer {
	position:absolute;
	width:200px;
	height:500px;
	z-index:3;
	left: 11px;
	top: 77px;
	background-color: #FF6600;
}
#EditR1 {
	position:absolute;
	width:878px;
	height:500px;
	z-index:4;
	left: 221px;
	top: 77px;
}
.STYLE3 {color: #0000CC}
#Layer1 {
	position:absolute;
	width:181px;
	height:217px;
	z-index:1;
	left: 2px;
	top: 2px;
}
.STYLE4 {
	font-size: 18px;
	font-weight: bold;
}
-->
</style><script type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
//-->
</script>
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
</head>

<body>
<center>
  <div id="Title1">
    <table width="1092" height="59" bgcolor="#FF6600">
      <tr>
        <td rowspan="2" class="CircleU"><div align="left"><?php echo "<a href=\"index.php\">"; ?> <span class="STYLE3">CircleU</a></span></div></td>
        <td width="128"><?php echo "<a href=\"index.php\">"; ?> </a></td>
        <td width="111"><div align="right"><?php echo "<a href=\"SignOut.php\">"; ?>Sign Out </a></div></td>
        <td width="120"><div align="center"><?php echo "<a href=\"ContactUs.php\">"; ?>Contact Us</a></div></td>
      </tr>
      <tr>
        <td><form id="form2" name="form2" method="post" <?php echo "action=\"AdminAdvancedSearch.php\""; ?>>
          <label>
            <input type="submit" name="AdvancedSearch" value="Advanced Search" />
          </label>
        </form>
        </td>
        <td colspan="2"><form id="form1" name="form1" method="post" <?php echo "action=\"AdminSearchResult.php\""; ?>>
          <label>
            <input type="text" name="search_text" />
          </label>
          <label>
          <input type="submit" name="Search" value="Search" />
          </label>
        </form>        </td>
      </tr>
    </table>
  </div>
  <div class="copyright">
<p>Copyright @ 2011 CircleU built in University of Florida. All right reserved&#13;</p>

</div>
  <div id="LeftLayer">
    <div id="Layer1">
	 <h3>Welcome, <?php echo $admin["FIRST_NAME"];?>!</h3>
      <table width="180" height="73" border="1">
	    <tr>
		  <td colspan="2" align="center" valign="middle">
			  <?php echo "<img src=\"". $admin["PROFILE_PIC"] . "\" width=\"180\" height=\"120\" />";?>
		  </td>
		</tr>
        <tr>
          <td width="76" height="34">Admin ID: </td>
          <td width="105"><?php echo $_SESSION["AdminID"]; ?></td>
        </tr>
        <tr>
          <td height="31">Name: </td>
          <td><?php echo $admin["FIRST_NAME"] . " " . $admin["LAST_NAME"];?></td>
        </tr>
      </table>
	<?php 
		echo "<p><a href=\"AdminHome.php\">Main Menu</a></p>";
		oci_close($connection);
	?>
    </div>
    
  
  </div>
  <div id="EditR1"><!-- InstanceBeginEditable name="EditRegion3" -->
  <div id="Layer3">
    <form  action="adminAddCourse.php" method="POST" id="add_form" name="form1" method="post" action="">
      <h4> Add Course</h4>
      <table width="350" border="1">
        <tr>
          <td width="142">Course ID: <font color=#FF3300>*</font></td>
          <td width="142"><input type="text" name="CourseID" 
		  	<?php if(isset($_POST["CourseID"])) echo "value='" . $_POST["CourseID"] . "'";?> /></td>
        </tr>
        <tr>
          <td>Course Name: <font color=#FF3300>*</font></td>
          <td><input type="text" name="CourseName" maxlength="60"  
		  	<?php if(isset($_POST["CourseName"])) echo "value='" . $_POST["CourseName"] . "'"; ?>  /></td>
        </tr>
		<tr>
          <td>Semester: <font color=#FF3300>*</font></td>
          <td align=left><select name="Semester" width="142">
				  <option value="NULL" 
				  <?php if(!isset($_POST["Semester"]) || $_POST["Semester"]=='NULL') echo "selected=\"selected\""; ?>>--</option>
				  <option value="Fall11" 
				  <?php if(isset($_POST["Semester"]) && $_POST["Semester"]=='Fall11') echo "selected=\"selected\""; ?>>Fall'11</option>
 				  <option value="Spring12" 
				  <?php if(isset($_POST["Semester"]) && $_POST["Semester"]=='Spring12') echo "selected=\"selected\""; ?>>Spring'12</option>
 				  <option value="Summer12" 
				  <?php if(isset($_POST["Semester"]) && $_POST["Semester"]=='Summer12') echo "selected=\"selected\""; ?>>Summer'12</option>
  				  <option value="Fall12" 
				  <?php if(isset($_POST["Semester"]) && $_POST["Semester"]=='Fall12') echo "selected=\"selected\""; ?>>Fall'12</option>
			  </select> 
		   </td>
        </tr>
        <tr>
          <td>Instructor name: </td>
          <td><input type="text" name="Inname" maxlength="50" 
		  	 <?php if(isset($_POST["Inname"])) echo "value='" . $_POST["Inname"] . "'"; ?>  /></td>
        </tr>
        <tr>
          <td>Location:</td>
          <td><input type="text" name="Location" maxlength="50" 
		  	<?php if(isset($_POST["Location"])) echo "value='" . $_POST["Location"] . "'"; ?>  /></td>
        </tr>
		<tr>
          <td>Lecture Time:</td>
          <td><input type="text" name="Time" maxlength="50" 
		  	<?php if(isset($_POST["Time"])) echo "value='" . $_POST["Time"] . "'";?>  /></td>
        </tr>
        <tr>
          <td>Textbook:</td>
          <td><input type="text" name="Textbook" maxlength="100" 
		  	<?php if(isset($_POST["Textbook"])) echo "value='" . $_POST["Textbook"] . "'";?>  /></td>
        </tr>
        <tr>
          <td>TA:</td>
          <td><input type="text" name="TA" maxlength="100" 
		  	<?php if(isset($_POST["TA"])) echo "value='" . $_POST["TA"] . "'";?>  /></td>
        </tr>
		<tr>
          <td>Office Hours:</td>
          <td><input type="text" name="Officehours" maxlength="100" 
		  	<?php if(isset($_POST["Officehours"])) echo "value='" . $_POST["Officehours"] . "'";?>  /></td>
        </tr>
		<tr>
          <td>Description:</td>
          <td><TEXTAREA name="Description" ROWS=4  COLS=20><?php if(isset($_POST["Description"])) echo  $_POST["Description"];?></TEXTAREA><br /></td>
        </tr>
      </table>
      <p>
        <input type="submit" name="submit" value="Add Course" />
        <input type="button" name="reset" value="Cancel" onclick="location.href='AdminHome.php'" />
      </p>
    </form>
	<center>
		<?php
		if($check_failed) echo "<font color=red><b>". $error_msg . "</b></font>";
		elseif($course_added) echo "<font color=green><b>". "Course is added." . "</b></font>";
		?>
	</center>
    </div>
  <!-- InstanceEndEditable --></div>
</center>
</body>
<!-- InstanceEnd --></html>
